<?php

namespace app\api\controller;

use app\api\model\LangClassLesson AS LessonModel;
use app\api\model\OauthOrderClass;
use app\api\validate\Page;

class LangClassLesson extends Base
{
    /**
     * 获取所有节课列表
     * @param int $classId 班级id
     * @return array
     * @throws \think\Exception\DbException
     */
    public function index($classId)
    {
        // 课程类型（语音课1，基础课2，高级课3）
        $type = input('type') ? input('type') : LessonModel::COURSE_VOICE;
        $page = $data['page'] = input('page') ? input('page') : 1;
        $size = $data['size'] = input('size') ? input('size') : $this->pageSize;

        // 检测变量
        $validate = new Page();
        if (!$validate->check($data)) {
            return self::sendResult(102, [], $validate->getError());
        }

        // 判断是否已经购买
        $oauthId = $this->oauthInfo['id'];
        $buy = OauthOrderClass::getOneByClass($oauthId, $classId);
        if (empty($buy)) {
            return self::sendResult(109);
        }

        $model = LessonModel::getList($classId, $type, $page, $size);
        return self::sendResult(self::$okCode, $model);
    }
}